<?php
namespace app\cms\controller;

use think\Db;
use think\Exception;
use think\Loader;
use think\Cache;

class Test
{
    /*
     * 商品同步 每天执行一次
     * 2017/8/8 蒋佳林 ADD
     *
     * */
    public function run()
    {
        DB::startTrans();
        try {
            DB::table('homegarden_cms.admin')->where('id=1')->setField('password', '1234567');
            DB::table('homegarden_cms.admin')->where('id=1')->setField('pwd', '12345678');
            DB::commit();
        } catch (Exception $e) {
            DB::rollback();
            return $e->getMessage();
        }
    }

    public function run2()
    {
        $db = DB::connect('homegarden_cms');
        $db->startTrans();
        try {
            $db->table('admin')->where('id=1')->setField('password', '1234567');
            $db->table('admin')->where('id=1')->setField('pwd', '12345678');
            $db->commit();
        } catch (Exception $e) {
            $db->rollback();
            return $e->getMessage();
        }
    }

    public function run3()
    {
        $message = \think\Loader::controller('unit/Message');
        $message->send();
    }

    public function run4()
    {
        $options = [
            'type' => 'redis',
            'expire' => 0,
            'prefix' => 'think',
//            'path'  =>  APP_PATH.'runtime/cache/'
            'host' => '114.215.45.11',
            'port' => 6379,
            'password' => 'LNxzd2017'
        ];
        Cache::connect($options);
        Cache::set('testername', 'jiangjialin');
        $t = Cache::get('testername');
        print_r($t);
    }
}
